package com.timoon.webcomponent.utility.slide;

import java.util.List;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.request.resource.PackageResourceReference;
import org.apache.wicket.spring.injection.annot.SpringBean;

import com.timoon.component.behavior.slidepic.slidepic1.AbstractSlidepic1Behavior;
import com.timoon.sample.dao.model.InfoSort;

/**
 *<p></p>
 *<p></p>
 *<p>Copyright:Copyright(c)2013.4.1</p>
 *<p>Company:timoon</p>
 *@author 付乐天
 *@version 1.0 */
public class Slide1Panel extends Panel {
	
	@SpringBean(name="com.timoon.sample.service.Slide1ServiceImpl")
	private Slide1Service service;
	
	private Class<? extends WebPage> targetPage;
	
	private Integer type;

	public Slide1Panel(String id,Integer type,Class<? extends WebPage> targetPage) {
		super(id);
		// TODO Auto-generated constructor stub
		
		this.type=type;
		
		this.targetPage=targetPage;
		
		renderPanel();
	}

	private void renderPanel() {
		// TODO Auto-generated method stub
		
		List<InfoSort> infoSorts=this.service.getInfoSortsByType(type);
		
		if(infoSorts!=null){
			if(infoSorts.size()!=4){
				throw new RuntimeException("根据type="+type+"获取到infosorts大小不为四，而为"+infoSorts.size());
			}
		}else{
			throw new RuntimeException("根据type="+type+"获取到infosorts为空");
		}
		for(int i=1;i<5;i++){
			PageParameters opt=new PageParameters();
			opt.set("info_sort_id", infoSorts.get(i-1).getId());
			BookmarkablePageLink link=new BookmarkablePageLink("wk_link"+i, targetPage,opt);
			add(link);
			Image img=new Image("wk_img"+i,new PackageResourceReference(this.getClass(),"name.jpg"));
			img.add(new AttributeModifier("alt",infoSorts.get(i-1).getRemark()));
			link.add(img);
		}
		this.add(new AbstractSlidepic1Behavior("#KinSlideshow"));
	}

}
